+2004-02-24 Federico Mena Quintero <federico@ximian.com>
+
+ * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+ from create_shortcuts_model().
+ (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+ to shortcuts_list.
+ (shortcuts_list_create): Renamed from shortcuts_tree_create().
+ (create_file_list): Enable the tree view as a model drag source.
+ (create_folder_tree): Likewise.
+
+ * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+ Register the drag source interface.
+ (drag_source_iface_init): New function.
+ (drag_source_row_draggable): New function.
+ (drag_source_drag_data_get): New function.
+
Tue Feb 24 19:12:07 2004 Owen Taylor <otaylor@redhat.com>
* === Released 2.3.4 ===
+2004-02-24 Federico Mena Quintero <federico@ximian.com>
+
+ * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+ from create_shortcuts_model().
+ (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+ to shortcuts_list.
+ (shortcuts_list_create): Renamed from shortcuts_tree_create().
+ (create_file_list): Enable the tree view as a model drag source.
+ (create_folder_tree): Likewise.
+
+ * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+ Register the drag source interface.
+ (drag_source_iface_init): New function.
+ (drag_source_row_draggable): New function.
+ (drag_source_drag_data_get): New function.
+
Tue Feb 24 19:12:07 2004 Owen Taylor <otaylor@redhat.com>
* === Released 2.3.4 ===
+2004-02-24 Federico Mena Quintero <federico@ximian.com>
+
+ * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+ from create_shortcuts_model().
+ (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+ to shortcuts_list.
+ (shortcuts_list_create): Renamed from shortcuts_tree_create().
+ (create_file_list): Enable the tree view as a model drag source.
+ (create_folder_tree): Likewise.
+
+ * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+ Register the drag source interface.
+ (drag_source_iface_init): New function.
+ (drag_source_row_draggable): New function.
+ (drag_source_drag_data_get): New function.
+
Tue Feb 24 19:12:07 2004 Owen Taylor <otaylor@redhat.com>
* === Released 2.3.4 ===
+2004-02-24 Federico Mena Quintero <federico@ximian.com>
+
+ * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+ from create_shortcuts_model().
+ (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+ to shortcuts_list.
+ (shortcuts_list_create): Renamed from shortcuts_tree_create().
+ (create_file_list): Enable the tree view as a model drag source.
+ (create_folder_tree): Likewise.
+
+ * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+ Register the drag source interface.
+ (drag_source_iface_init): New function.
+ (drag_source_row_draggable): New function.
+ (drag_source_drag_data_get): New function.
+
Tue Feb 24 19:12:07 2004 Owen Taylor <otaylor@redhat.com>
* === Released 2.3.4 ===
+2004-02-24 Federico Mena Quintero <federico@ximian.com>
+
+ * gtk/gtkfilechooserdefault.c (shortcuts_model_create): Renamed
+ from create_shortcuts_model().
+ (struct _GtkFileChooserDefault): Renamed the shortcuts_tree field
+ to shortcuts_list.
+ (shortcuts_list_create): Renamed from shortcuts_tree_create().
+ (create_file_list): Enable the tree view as a model drag source.
+ (create_folder_tree): Likewise.
+
+ * gtk/gtkfilesystemmodel.c (_gtk_file_system_model_get_type):
+ Register the drag source interface.
+ (drag_source_iface_init): New function.
+ (drag_source_row_draggable): New function.
+ (drag_source_drag_data_get): New function.
+
Tue Feb 24 19:12:07 2004 Owen Taylor <otaylor@redhat.com>
* === Released 2.3.4 ===
GtkWidget *tree_scrollwin;
GtkWidget *tree;
GtkWidget *shortcuts_scrollwin;
- GtkWidget *shortcuts_tree;
+ GtkWidget *shortcuts_list;
GtkWidget *add_bookmark_button;
GtkWidget *remove_bookmark_button;
GtkWidget *list_scrollwin;
static guint signals[LAST_SIGNAL] = { 0 };
-/* Column numbers for the shortcuts tree. Keep these in sync with create_shortcuts_model() */
+/* Column numbers for the shortcuts tree. Keep these in sync with shortcuts_model_create() */
enum {
SHORTCUTS_COL_PIXBUF,
SHORTCUTS_COL_NAME,
{
GtkTreeSelection *selection;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
gtk_tree_selection_unselect_all (selection);
}
}
static void
-create_shortcuts_model (GtkFileChooserDefault *impl)
+shortcuts_model_create (GtkFileChooserDefault *impl)
{
if (impl->shortcuts_model)
g_object_unref (impl->shortcuts_model);
shortcuts_add_bookmarks (impl);
}
- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_tree), GTK_TREE_MODEL (impl->shortcuts_model));
+ gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_list), GTK_TREE_MODEL (impl->shortcuts_model));
}
/* Callback used when the "New Folder" toolbar button is clicked */
impl->tree = gtk_tree_view_new ();
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
+ gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->tree),
+ GDK_BUTTON1_MASK,
+ shortcuts_targets,
+ num_shortcuts_targets,
+ GDK_ACTION_COPY);
+
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
g_signal_connect (selection, "changed",
G_CALLBACK (tree_selection_changed), impl);
gboolean removable;
GError *error;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
{
GtkTreeIter iter;
gboolean removable = FALSE;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
/* Creates the widgets for the shortcuts and bookmarks tree */
static GtkWidget *
-shortcuts_tree_create (GtkFileChooserDefault *impl)
+shortcuts_list_create (GtkFileChooserDefault *impl)
{
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
/* Tree */
- impl->shortcuts_tree = gtk_tree_view_new ();
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_tree), FALSE);
+ impl->shortcuts_list = gtk_tree_view_new ();
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_list), FALSE);
- gtk_drag_dest_set (impl->shortcuts_tree,
+ gtk_drag_dest_set (impl->shortcuts_list,
GTK_DEST_DEFAULT_ALL,
shortcuts_targets,
num_shortcuts_targets,
GDK_ACTION_COPY);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_list));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
gtk_tree_selection_set_select_function (selection,
shortcuts_select_func,
g_signal_connect (selection, "changed",
G_CALLBACK (shortcuts_selection_changed_cb), impl);
- g_signal_connect (impl->shortcuts_tree, "row-activated",
+ g_signal_connect (impl->shortcuts_list, "row-activated",
G_CALLBACK (shortcuts_row_activated_cb), impl);
- g_signal_connect (impl->shortcuts_tree, "drag-data-received",
+ g_signal_connect (impl->shortcuts_list, "drag-data-received",
G_CALLBACK (shortcuts_drag_data_received_cb), impl);
- gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_tree);
- gtk_widget_show (impl->shortcuts_tree);
+ gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_list);
+ gtk_widget_show (impl->shortcuts_list);
/* Model */
- create_shortcuts_model (impl);
+ shortcuts_model_create (impl);
/* Column */
"text", SHORTCUTS_COL_NAME,
NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_tree), column);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_list), column);
return impl->shortcuts_scrollwin;
}
/* Shortcuts tree */
- widget = shortcuts_tree_create (impl);
+ widget = shortcuts_list_create (impl);
gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
/* Box for buttons */
G_CALLBACK (list_row_activated), impl);
gtk_widget_show (impl->list);
+ gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->list),
+ GDK_BUTTON1_MASK,
+ shortcuts_targets,
+ num_shortcuts_targets,
+ GDK_ACTION_COPY);
+
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
g_signal_connect (selection, "changed",
G_CALLBACK (list_selection_changed), impl);
#include "gtkfilesystemmodel.h"
#include "gtkfilesystem.h"
#include "gtkintl.h"
+#include "gtktreednd.h"
#include "gtktreemodel.h"
typedef struct _GtkFileSystemModelClass GtkFileSystemModelClass;
static void gtk_file_system_model_init (GtkFileSystemModel *model);
static void gtk_file_system_model_finalize (GObject *object);
+static void drag_source_iface_init (GtkTreeDragSourceIface *iface);
+
static GtkTreeModelFlags gtk_file_system_model_get_flags (GtkTreeModel *tree_model);
static gint gtk_file_system_model_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_file_system_model_get_column_type (GtkTreeModel *tree_model,
static void gtk_file_system_model_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
+static gboolean drag_source_row_draggable (GtkTreeDragSource *drag_source,
+ GtkTreePath *path);
+static gboolean drag_source_drag_data_get (GtkTreeDragSource *drag_source,
+ GtkTreePath *path,
+ GtkSelectionData *selection_data);
+
static FileModelNode *file_model_node_new (GtkFileSystemModel *model,
const GtkFilePath *path);
static void file_model_node_free (FileModelNode *node);
static const GInterfaceInfo file_system_info =
{
(GInterfaceInitFunc) gtk_file_system_model_iface_init, /* interface_init */
- NULL, /* interface_finalize */
- NULL /* interface_data */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ static const GInterfaceInfo drag_source_info =
+ {
+ (GInterfaceInitFunc) drag_source_iface_init, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
};
file_system_model_type = g_type_register_static (G_TYPE_OBJECT,
g_type_add_interface_static (file_system_model_type,
GTK_TYPE_TREE_MODEL,
&file_system_info);
+ g_type_add_interface_static (file_system_model_type,
+ GTK_TYPE_TREE_DRAG_SOURCE,
+ &drag_source_info);
}
return file_system_model_type;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+static void
+drag_source_iface_init (GtkTreeDragSourceIface *iface)
+{
+ iface->row_draggable = drag_source_row_draggable;
+ iface->drag_data_get = drag_source_drag_data_get;
+ iface->drag_data_delete = NULL;
+}
+
/*
* ******************** GtkTreeModel methods ********************
*/
iter->user_data);
}
+static gboolean
+drag_source_row_draggable (GtkTreeDragSource *drag_source,
+ GtkTreePath *path)
+{
+ GtkFileSystemModel *model;
+ GtkTreeIter iter;
+ FileModelNode *node;
+
+ model = GTK_FILE_SYSTEM_MODEL (drag_source);
+
+ if (!gtk_file_system_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
+ return FALSE;
+
+ if (!model->has_editable)
+ return TRUE;
+
+ node = iter.user_data;
+ return (node != model->roots);
+}
+
+static gboolean
+drag_source_drag_data_get (GtkTreeDragSource *drag_source,
+ GtkTreePath *path,
+ GtkSelectionData *selection_data)
+{
+ GtkFileSystemModel *model;
+ GtkTreeIter iter;
+ const GtkFilePath *file_path;
+ char *uri;
+ char *uris;
+
+ model = GTK_FILE_SYSTEM_MODEL (drag_source);
+
+ if (!gtk_file_system_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
+ return FALSE;
+
+ file_path = _gtk_file_system_model_get_path (model, &iter);
+ g_assert (file_path != NULL);
+
+ uri = gtk_file_system_path_to_uri (model->file_system, file_path);
+ uris = g_strconcat (uri, "\r\n", NULL);
+
+ gtk_selection_data_set (selection_data,
+ gdk_atom_intern ("text/uri-list", FALSE),
+ 8,
+ uris,
+ strlen (uris) + 1);
+
+ g_free (uri);
+ g_free (uris);
+
+ return TRUE;
+}
+
/**
* _gtk_file_system_model_new:
* @file_system: an object implementing #GtkFileSystem